<#import "../../common/layout.ftl" as l>


<@l.content>

<script>
    var crud = {
//        read: "/manage/ship/detail",
//        update: '/manage/ship/update',
//        del: "/manage/ship/delete"
    };
    var model = [
//        {name : 'id',type : 'hidden',text : '地理点编号',allowBlank : true,primaryKey : true},
//        {name : 'name',type : 'text',text : '地理点名称',allowBlank : false,primaryKey : false},
//        {name : 'shipEnName',type : 'text',text : '船舶英文名',allowBlank : false,primaryKey : false},
//        {name : 'callSign',type : 'text',text : '船舶呼号',allowBlank : false,primaryKey : false},
//        {name : 'nation',type : 'text',text : '国籍',allowBlank : false,primaryKey : false},
//        {name : 'tonnage',type : 'number',text : '吨位',allowBlank : false,primaryKey : false},
//        {name : 'power',type : 'number',text : '主机功率',value:0,allowBlank : false,primaryKey : false},
//        {name : 'shipLength',type : 'number',text : '船舶长度',allowBlank : false,primaryKey : false},
//        {name : 'draftAfter',type : 'number',text : '后吃水',allowBlank : false,primaryKey : false},
//        {name : 'draftMax',type : 'number',text : '最大吃水',allowBlank : false,primaryKey : false},
//        {name : 'draftForward',type : 'number',text : '前吃水',allowBlank : false,primaryKey : false}
    ];



</script>


<form id="pagination-form" method="post" action="/manage/map/server/publishShip">

    <input type="hidden" name="page" value="${pageInfo.pageNum}">
    <input type="hidden" name="limit" value="${pageInfo.pageSize}">
    <input type="hidden" name="totalPage" value="${pageInfo.pages}">

    <div class="ibox">
        <div class="ibox-title">
            <h3><#if Session['currentMenu']??>${Session['currentMenu'].name}<#else></#if></h3>

        <#--<div class="ibox-tools">-->
        <#--<a href="#" id="pagination-add">-->
        <#--<i class="fa fa-plus"></i>-->
        <#--添加-->
        <#--</a>-->
        <#--<a id="pagination-edit" href="#">-->
        <#--<i class="fa fa-edit"></i>-->
        <#--编辑-->
        <#--</a>-->

        <#--<a id="pagination-delete" href="#">-->
        <#--<i class="fa fa-trash"></i>-->
        <#--删除-->
        <#--</a>-->

        <#--</div>-->
        </div>
        <div class="ibox-content">
            <div class="input-group search-content">
                <input type="text" name="key" value="<#if key??>${key}<#else></#if>" class="form-control"  style="width: 250px" placeholder="请输入船名、MMSI或关键字"> <span class="input-group-btn">
                <input type="submit" class="btn btn-primary" value="搜索">
            </span></div>
            <div>
                <div class="table-responsive">
                    <table class="table table-striped table-hover dataTables-example" >
                        <thead>
                        <tr>
                        <#--<th>&nbsp;</th>-->
                            <th>船名</th>
                            <th>MMSI</th>
                            <th>船舶类型</th>
                            <th>国籍</th>
                            <th>服务类型</th>
                            <th>服务内容</th>
                            <th>服务状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>

                        <tbody>
                            <#list pageInfo.list as report>
                            <tr>
                            <#--<td><input type="checkbox" class="i-checks" value="<#if report.id??>${report.id}<#else></#if>"></td>-->
                                <td><#if report.cyxShip.shipName??>${report.cyxShip.shipName}<#else></#if></td>
                                <td><#if report.cyxShip.mmsi??>${report.cyxShip.mmsi}<#else></#if></td>
                                <td><#if report.cyxShip.shipType??>${report.cyxShip.shipType}<#else></#if></td>
                                <td><#if report.cyxShip.nation??>${report.cyxShip.nation}<#else></#if></td>
                                <td><#if report.shipServer.serverType?? >${report.shipServer.serverType}<#else></#if></td>
                                <td style="width: 20%;word-break: break-all"><#if report.shipServer.message?? >${report.shipServer.message}<#else></#if></td>
                                <td><#if report.shipServer.status??><#if report.shipServer.status=="0">待审核<#elseif report.shipServer.status=="1">已发布
                                <#elseif report.shipServer.status=="2">未通过</#if><#else>未发布</#if></td>
                                <td>
                                    <#if report.shipServer.ssid??><#if  report.shipServer.status=="2"><a onclick="publishServer('${report.guid}','${report.shipServer.ssid}')" href="#">发布服务</a>&nbsp;|&nbsp;</#if>
                                        <a onclick="deleteServer('${report.shipServer.ssid}')" href="#">删除服务</a>
                                <#else><a onclick="publishServer('${report.guid}')" href="#">发布服务</a></#if></td>
                            </tr>
                            </#list>
                        </tbody>
                    </table>
                </div>
                <div class="pagination-content">
                    <div id="pagination" class="pagination">
                    </div>
                </div>
            </div>
        </div>

    </div>
</form>


</@l.content>

<script src="/pagination/js/pagination.js"></script>
<script>

    $.ajax({
        type: "POST",
        url: "/manage/server/water",
        dataType: "json",
        success: function (data) {
             console.log(data);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log(errorThrown);
        }
    });


    function deleteServer(id) {
        layer.confirm("确认删除选中数据",{btn:['确定','取消']},function () {
            $.ajax({
                type: "POST",
                url: "/manage/map/server/dropServer",
                data: {ssid:id
                },
                dataType: "json",
                success: function (data) {
                    if (data.success) {
                        layer.msg("删除成功");
                        setTimeout(function(){location.reload()},500);
                    }
                }
            });
        },function () {
            layer.closeAll();
        })
    }


    function type() {
        var str = "";
        $.ajax({
            type: "POST",
            async:false,
            url: "/manage/map/type/selecttype",
            data: {},
            dataType: "json",
            success: function (data) {
                for (var i = 0; i < data.length; i++) {
                    str = str + "<option value='" + data[i].typetext + "'>" + data[i].typetext + "</option>";
                }
            }
        });
        return str;
    }

    function publishServer(guid,ssid) {
        var ss= type();
        var info = " <div class='form-group'>" +
                "<label for='selectserver' class='col-sm-3 control-label'>服务类型</label>" +
                "<div class='col-sm-9'>" +
                "<select class='form-control' name='selectserver' id='selectserver'>" +
                ss +
                "</select>" +
                "</div>" +
                "</div>";
        info += "<div class='form-group'>" +
                "<label for='keyword' class='col-sm-3 control-label'>关键字</label>" +
                "<div class='col-sm-9'>" +
                "<input class='form-control' id='keyword' type='text' placeholder='逗号隔开，最多五个字符，最多三个'/>" +
                "</div>" +
                "</div>"
        info += "<div class='form-group'>" +
                "<label for='txtContent' class='col-sm-3 control-label'>服务内容</label>" +
                "<div class='col-sm-9'>" +
                "<textarea class='form-control'  id='txtContent' rows='5' ></textarea>" +
                "</div>" +
                "</div>";

        var index= layer.open({
            type: 1, //page层
            area: ['500px'],
            title: '发布服务',
            shade: 0, //遮罩透明度
            moveType: 1, //拖拽风格，0是默认，1是传统拖动
            shift: 1, //0-6的动画形式，-1不开启
            maxmin: true, //开启最大化最小化按钮
            content: '<form class="form-horizontal" style="padding: 20px;" data-parsley-validate novalidate>'
            + info +
            '</form>',
            btn: ['发布', '关闭'] //只是为了演示
            ,success:function () {
                $.ajax({
                    type: "POST",
                    url: "/manage/map/server/detail",
                    data: {ssid:ssid},
                    dataType: "json",
                    success: function (data) {
                        if (data) {
                            $("#selectserver").val(data.serverType);
                            $("#keyword").val(data.keyword);
                            $("#txtContent").val(data.message)
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        console.log(errorThrown);
                    }
                });
            }
            , yes: function(){
                var serverType = $("#selectserver").find("option:selected").text();
                var keyword = $("#keyword").val();
                var message = $("#txtContent").val();
                var   prop= {
                    ssid:ssid,
                    serverType: serverType,
                    keyword: keyword,
                    message: message,
                    guid: guid,
                    status:'0'
                }

                if (serverType == "" || message == "" || serverType == "==请选择==") {
                    layer.msg("类型和内容不能为空");
                }else {
                    $.ajax({
                        type: "POST",
                        url: "/manage/map/server/saveserver",
                        data: prop,
                        dataType: "json",
                        success: function (data) {
                            if (data.result == true) {
                                layer.msg("发布成功");
                                layer.close(index);
                                setTimeout(function(){location.reload()},500);
                            }else {
                                if(data.keyword == false){
                                    layer.msg("关键字过长");
                                }else {
                                    layer.msg("发布失败");
                                }
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            console.log(errorThrown);
                        }
                    });

                }


            }
            ,btn2: function(){
                layer.closeAll();
            }
        });
    }
</script>